<?php


namespace app\controller;


use app\common\constants\AppConstants;
use app\common\controller\ApiController;
use app\common\util\MessageRobot;
use app\common\util\Response;
use think\response\Json;

class MessageRobotExample extends ApiController
{
    /**
     * 企业微信机器人
     * @return Json
     */
    public function wechat(): Json
    {
        $obj = new MessageRobot();
        $content = [
            'content' => '企业微信机器人测试'
        ];
        $data = $obj->getWechatMsgTpl('text', $content);
        $obj->wechat(AppConstants::WE_CHAT_ROBOT_KEY, $data);

        return Response::successJson();
    }

    /**
     * 钉钉机器人
     * @return Json
     */
    public function dingTalk(): Json
    {
        $obj = new MessageRobot();
        $content = [
            'content' => '钉钉机器人测试'
        ];
        $at = [
            //根据电话@
            'atMobiles' => [
                '130xxxxxx'
            ],
            //根据用户id@
            'atUserIds' => [
                'user111'
            ],
            //是否@所有人
            'isAtAll' => false
        ];
        $data = $obj->getDingTalkMsgTpl('text', $content, $at);

        (new MessageRobot())->dingTalk(AppConstants::DING_TALK_ROBOT_ACCESS_TOKEN, AppConstants::DING_TALK_ROBOT_SECRET, $data);
        return Response::successJson();
    }

}